<div class="form">

	<?php
	$properties = array(
		'id'=>'leave-form',
		'enableAjaxValidation'=>true,
		'focus'=>array($model, 'employeeId'),
	);
	$form = $this->beginWidget('CActiveForm', $properties);
	?>

	<p class="note">
		Fields with <span class="required">*</span> are required.
	</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'employeeId');
		$criteria = array(
			'order'=>'name',
		);
		$models = Employee::model()->findAll($criteria);
		$data = CHtml::listData($models, 'id', 'name');
		$htmlOptions = array(
			'empty'=>''
		);
		if (!$model->isNewRecord) {
			$htmlOptions['disabled'] = 'disabled';
		}
		echo $form->dropDownList($model, 'employeeId', $data, $htmlOptions);
		echo $form->error($model, 'employeeId');
		?>

		<?php
		$htmlOptions = array(
			'id'=>'history',
			'class'=>$model->employeeId ? '' : 'hide',
			'target'=>'_blank',
		);
		$url = array(
			'_history',
			'employeeId'=>$model->employeeId,
		);
		echo CHtml::link('History', $url, $htmlOptions);
		?>
	</div>

	<div class="row">
		<?php
		echo $form->label($model, 'balance');
		$htmlOptions = array(
			'size'=>3,
		);
		if ($model->isNewRecord) {
			$htmlOptions['readonly'] = 'readonly';
		}
		echo $form->textField($model, 'balance', $htmlOptions);
		echo $form->error($model, 'balance');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'name');
		$data = array(
			Leave::NAME_ANNUALY=>Leave::NAME_ANNUALY,
			Leave::NAME_CONDOLENCE=>Leave::NAME_CONDOLENCE,
			Leave::NAME_MARRIAGE=>Leave::NAME_MARRIAGE,
			Leave::NAME_MATERNITY=>Leave::NAME_MATERNITY,
			Leave::NAME_SICK=>Leave::NAME_SICK,
			Leave::NAME_FAMILY_MATTER=>Leave::NAME_FAMILY_MATTER,
			Leave::NAME_OTHER=>Leave::NAME_OTHER,
		);
		$htmlOptions = array('empty'=>'');
		echo $form->dropDownList(
			$model, 'name', $data, $htmlOptions
		);
		echo $form->error($model, 'name');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'debit');
		$htmlOptions = array(
			'size'=>3,
			'maxlength'=>3,
		);
		echo $form->textField($model, 'debit', $htmlOptions);
		echo $form->error($model, 'debit');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'start');
		$options = array(
			'model'=>$model,
			'attribute'=>'start',
			'options'=>array(
				'dateFormat'=>'yy-mm-dd',
				'changeMonth'=>true,
				'changeYear'=>true,
			),
			'htmlOptions'=>array(
				'style'=>'height:20px;'
			),
		);
		$this->widget('zii.widgets.jui.CJuiDatePicker', $options);
		echo $form->error($model, 'start');
		?>
	</div>

	<div class="row full">
		<?php
		echo $form->labelEx($model, 'note');
		echo $form->textArea($model, 'note', array('rows'=>6, 'cols'=>50));
		echo $form->error($model, 'note');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'status');
		$data = array(
			Leave::STATUS_APPROVED_MANAGEMENT=>Leave::STATUS_APPROVED_MANAGEMENT,
			Leave::STATUS_APPROVED_SUPERVISOR=>Leave::STATUS_APPROVED_SUPERVISOR,
			Leave::STATUS_CANCELED=>Leave::STATUS_CANCELED,
			Leave::STATUS_PENDING=>Leave::STATUS_PENDING,
			Leave::STATUS_REJECTED_MANAGEMENT=>Leave::STATUS_REJECTED_MANAGEMENT,
			Leave::STATUS_REJECTED_SUPERVISOR=>Leave::STATUS_REJECTED_SUPERVISOR,
		);
		echo $form->dropDownList($model, 'status', $data);
		echo $form->error($model, 'status');
		?>
	</div>

	<div class="row buttons">
		<?php
		echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save');
		?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->

<?php
Yii::app()->clientScript->registerCoreScript('jquery');
Yii::app()->clientScript->registerCoreScript('jquery.ui');

$data = array(
	':employeeId'=>CHtml::activeId($model, 'employeeId'),
	':url'=>CHtml::normalizeUrl(array('_history')),
);
Yii::app()->clientScript->registerScriptContent(
	'history', 'application.views.leave._form', CClientScript::POS_READY, $data
);

$config = array(
	'scrolling'=>'auto',
	'titleShow'=>false,
	'transitionIn'=>'elastic',
	'transitionOut'=>'elastic',
	'easingIn'=>'easeOutBack',
	'easingOut'=>'easeInBack',
	'overlayColor'=>'#000',
	'showCloseButton'=>true,
	'autoDimensions'=>false,
	'width'=>800,
);
$this->widget('EFancyBox', array('target'=>'#history', 'config'=>$config));
?>
